<template>
  <!-- 安防-累计数据 security-accumulate -->
  <div class="real-monitor chart-box1">
    <div class="chart-title">实时视频</div>
    <div class="chart-content" align="middle">
      <a-row align="middle" :gutter="0" style="width: 100%; height: 100%">
        <a-col :span="16" class="monitor-left">
          <div class="monitor-left-item" @click="onVideoClick(0)">
            <template v-if="list[0]">
              <flvVideo
                :videoItem="list[0]"
                :videoIndex="0"
                v-if="list[0].video_type == 'flv'"
              />
              <hlsVideo
                :videoItem="list[0]"
                :videoIndex="0"
                v-if="list[0].video_type == 'hls'"
              />
            </template>
          </div>
        </a-col>
        <a-col :span="8" class="monitor-right">
          <div class="monitor-right-item" @click="onVideoClick(1)">
            <template v-if="list[1]">
              <flvVideo
                :videoItem="list[1]"
                :videoIndex="1"
                v-if="list[1].video_type == 'flv'"
              />
              <hlsVideo
                :videoItem="list[1]"
                :videoIndex="1"
                v-if="list[1].video_type == 'hls'"
              />
            </template>
          </div>
          <div class="monitor-right-item" @click="onVideoClick(2)">
            <template v-if="list[2]">
              <flvVideo
                :videoItem="list[2]"
                :videoIndex="2"
                v-if="list[2].video_type == 'flv'"
              />
              <hlsVideo
                :videoItem="list[2]"
                :videoIndex="2"
                v-if="list[2].video_type == 'hls'"
              />
            </template>
          </div>
        </a-col>
      </a-row>
    </div>

    <MonitorModal
      :visible="modalVisible"
      :videoInfo="currentVideo"
      @onClose="onModalClose"
    />
  </div>
</template>

<script>
import { defineComponent, nextTick, reactive, toRefs, watch } from "vue";
import common from "../../utils/common";
import request from "../../../../common/utils/request";
import store from "../../../../store";
import flvVideo from "./VideoCam/flvVideo.vue";
import hlsVideo from "./VideoCam/hlsVideo.vue";
import MonitorModal from "./components/MonitorModal.vue";

export default defineComponent({
  name: "RealMonitor",
  components: { flvVideo, hlsVideo, MonitorModal },
  setup(props) {
    let keyCount = 1;
    const state = reactive({
      chartKey: `current_peak_${keyCount}`,
      list: [],

      modalVisible: false,
      currentVideo: [],
    });

    watch(
      () => store.getters.security.ChannelTotal,
      (val) => {
        if (val) {
          getData();
        }
      }
    );

    const getData = () => {
      const { ChannelTotal } = store.getters.security;
      if (ChannelTotal && ChannelTotal.length) {
        state.list = ChannelTotal;
      }
    };
    getData();

    const onVideoClick = (index) => {
      if (state.list[index]) {
        state.currentVideo = [state.list[index]];
        state.modalVisible = true;
      }
    };

    const onModalClose = () => {
      state.modalVisible = false;
      state.currentVideo = [];
    };

    return {
      ...toRefs(state),
      onVideoClick,
      onModalClose,
    };
  },
});
</script>
<style lang="less" scoped>
@import "../../styles/common.less";

.monitor-left {
  height: 100%;
  padding-right: 1rem;

  .monitor-left-item {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0.4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: pointer;
  }
}
.monitor-right {
  height: 100%;

  .monitor-right-item {
    width: 100%;
    height: calc((100% - 1rem) / 2);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0.4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: pointer;

    &:last-child {
      margin-top: 1rem;
    }
  }
}
</style>
